﻿namespace AgileDashboard.AppCode
{
    using System.Collections.Generic;
    using System.Reflection;
    using System.Runtime.Serialization;

    using log4net;

    /// <summary>
    /// Simple DTO used to hold project data
    /// </summary>
    [DataContract(Name = "project")]
    public class Project : VersionOneEntity
    {
        private static Dictionary<string, string> versionOneAttributeNameDictionary;
        private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// Gets or sets the total story points remaining To Do in the Project
        /// </summary>
        [DataMember(Name = "toDoStoryPoints")]
        [VersionOneAttributeName("Workitems:PrimaryWorkitem[AssetState='64';AssetState!='Dead';IsDeleted='False'].Estimate.@Sum")]
        public double ToDoStoryPoints { get; set; }

        /// <summary>
        /// Gets or sets the total story points completed To Do in the Project
        /// </summary>
        [DataMember(Name = "doneStoryPoints")]
        [VersionOneAttributeName("Workitems:PrimaryWorkitem[AssetState='Closed';AssetState!='Dead';IsDeleted='False'].Estimate.@Sum")]
        public double DoneStoryPoints { get; set; }

        /// <summary>
        /// Gets or sets the total story points in the Project
        /// </summary>
        [DataMember(Name = "totalStoryPoints")]
        [VersionOneAttributeName("Workitems:PrimaryWorkitem[AssetState!='Dead';IsDeleted='False'].Estimate.@Sum")]
        public double TotalStoryPoints { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this project is configured to be shown in the dashboard
        /// </summary>
        [DataMember(Name = "displayInAgileDashboard")]
        [VersionOneAttributeName("Custom_DisplayInAgileDashboard")]
        public bool DisplayInAgileDashboard { get; set; }

        /// <summary>
        /// Gets or sets the name of the Project in Version One
        /// </summary>
        [DataMember(Name = "name")]
        [VersionOneAttributeName("Name")]
        public string Name { get; set; }

        public static Dictionary<string, string> VersionOneAttributeNameDictionary
        {
            get
            {
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Returning instance of Project Attribute Name Dictionary");
                }

                return versionOneAttributeNameDictionary ?? (versionOneAttributeNameDictionary = BuildVersionOneAttributeDictionary<Project>());
            }
        }
    }
}